﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TorchesTombs
{
    public class ItemQuantityMenuItem : ToolStripControlHost
    {
        //constructor
        public ItemQuantityMenuItem(ActionMenuItem ami)
            : base(new TrackBar())
        {
            LinkedItem = ami;
            _tb = Control as TrackBar;
            _tb.Minimum = 1;
            _tb.Maximum = ami.Quantity;
            _tb.Value = ami.Quantity;
            _tb.ValueChanged += tb_ValueChanged;
        }

        //value changed event
        private void tb_ValueChanged(object sender, EventArgs e)
        {
            LinkedItem.Quantity = _tb.Value;
            LinkedItem.UpdateText();
        }

        //unhook event
        public void UnHook()
        {
            _tb.ValueChanged -= tb_ValueChanged;
            _tb = null;
        }

        //public properties
        public ActionMenuItem LinkedItem { get; set; }

        //private members
        private TrackBar _tb;
    }
}
